package utils

import (
	"dta-apk/global"

	fsoSdk "zlifangyu.cn/dta-fso-sdk-go/client"
)

var fsoClient *fsoSdk.FsoClient

func getClient() *fsoSdk.FsoClient {
	if fsoClient == nil {
		fsoClient = &fsoSdk.FsoClient{
			FsoServer: global.Config.Fso.Server,
			ProjectId: global.Config.Fso.ProjectId,
			Secret:    global.Config.Fso.ProjectSecret,
			FsoType:   global.Config.Fso.FsoType,
			BasePath:  global.Config.Fso.BasePath,
		}
	}
	return fsoClient

}

// 上传文件
func PutFile(fileName, filePath string) string {
	fileUrl := getClient().PutObject(global.Config.Fso.Bucket, fileName, filePath)
	return fileUrl
}

// 获取文件访问路径
func GetFileUrl(fileName string) string {
	return getClient().GetObjectUrl(global.Config.Fso.Bucket, fileName)
}

// 下载文件
func DownloadFsoFile(fileName, filePath string) bool {
	return getClient().DownloadObject(global.Config.Fso.Bucket, fileName, filePath)
}
